// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const lightCodeTheme = require('prism-react-renderer/themes/github')
const darkCodeTheme = require('prism-react-renderer/themes/dracula')

const languageToLocaleMap = {
  'zh-Hans': 'zh_CN',
  en: 'en',
  en_US: 'en',
}

/** @type {import('@docusaurus/types').Config} */
const config = {
  title: 'PolyOS',
  // TODO Update slogan.
  tagline:
    'PolyOS is an intelligent mobile and AIoT operating system designed for the RISC-V architecture.',
  favicon: 'img/polyos-logo.png',
  url: 'https://polyos.iscas.ac.cn',
  baseUrl: '/',
  onBrokenLinks: 'throw',
  onBrokenMarkdownLinks: 'warn',
  i18n: {
    defaultLocale: 'zh-Hans',
    locales: ['en', 'zh-Hans'],
  },
  presets: [
    [
      'classic',
      /** @type {import('@docusaurus/preset-classic').Options} */
      ({
        docs: {
          sidebarPath: require.resolve('./sidebars.js'),
          // TODO update url of source editing. Edit page is unnecessary.
          editUrl: ({ docPath, locale }) =>
            `https://gitee.com/riscv-raios/polyos-docs/tree/main/${
              languageToLocaleMap[locale]
            }/${docPath.slice(0, -1)}`,
        },
        blog: {
          path: 'news',
          routeBasePath: 'news',
          showReadingTime: true,
        },
        theme: {
          customCss: require.resolve('./src/css/custom.css'),
        },
      }),
    ],
  ],

  themeConfig:
    /** @type {import('@docusaurus/preset-classic').ThemeConfig} */
    ({
      // our social card. In the static folder
      image: 'img/polyos-logo-en.png',
      navbar: {
        title: 'PolyOS',
        logo: {
          alt: 'PolyOS Logo',
          src: 'img/polyos-logo.png',
        },
        items: [
          {
            to: '/news',
            label: 'News',
            position: 'left',
          },
          {
            to: '/docs',
            type: 'dropdown',
            label: 'Document',
            position: 'left',
            items: [
              {
                label: 'PolyOS Mobile',
                href: '/docs',
              },
              {
                label: 'PolyOS AIoT',
                href: 'https://isrc.iscas.ac.cn/riscv-raios/docs/',
              },
            ],
          },
          {
            to: '/community',
            label: 'Community',
            position: 'left',
          },
          {
            to: '/get-polyos',
            label: 'Get PolyOS',
            position: 'right',
          },
          {
            label: 'PolyOS Editions',
            type: 'dropdown',
            position: 'right',
            items: [
              {
                label: 'PolyOS Mobile',
                href: '/polyos-mobile',
              },
              {
                label: 'PolyOS AIoT',
                href: 'https://isrc.iscas.ac.cn/riscv-raios/docs/',
              },
            ],
          },
          {
            type: 'localeDropdown',
            position: 'right',
            dropdownItemsAfter: [
              {
                type: 'html',
                value: '<hr style="margin: 0.3rem 0;">',
              },
            ],
          },
        ],
      },
      footer: {
        links: [
          {
            title: 'Docs',
            items: [
              {
                label: 'PolyOS Mobile',
                to: '/polyos-mobile',
              },
              {
                label: 'PolyOS AIoT',
                to: 'https://isrc.iscas.ac.cn/riscv-raios/docs/',
              },
              {
                label: 'Release Notes',
                to: '/docs/release-notes',
              },
            ],
          },
          {
            title: 'Community',
            items: [
              {
                label: 'Code of Conduct',
                to: '/code-of-conduct',
              },
              {
                label: 'WeChat/QQ Group',
                to: '/community',
              },
            ],
          },
          {
            title: 'More',
            items: [
              {
                label: 'Gitee',
                // update origin source repository url.
                href: 'https://gitee.com/riscv-raios',
              },
              {
                label: 'OpenHarmony',
                href: 'https://www.openharmony.cn/mainPlay',
              },
            ],
          },
        ],
        logo: {
          alt: 'copyright',
          src: 'img/full-logo-en.svg',
          width: 200,
          href: 'http://creativecommons.org/licenses/by/4.0/',
        },
        copyright: `Copyright © ${new Date().getFullYear()} PolyOS Project.`,
      },
      prism: {
        theme: lightCodeTheme,
        darkTheme: darkCodeTheme,
      },
    }),
}

module.exports = config
